﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GUI.Extensions;
using BO.News;
using BO.Infrastructure.Utils;
using Utilities.Entities;

namespace GUI.Services.News
{
    /// <summary>
    /// Summary description for GetLiveNews
    /// </summary>
    public class GetLiveNews : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            var ajaxResponse = new AjaxResponse();
            var newsId = RequestExtensions.NewsId;
            if (newsId > 0)
            {

                var lstLiveNews = NewsBO.GetInstance().GetLiveNews(newsId);

                if (lstLiveNews != null && lstLiveNews.Any())
                {
                    var closestItemId = PresentationUtils.Object2Integer(context.Request.QueryString["closestItemId"]);
                    var result = lstLiveNews.Where(item => item.Id > closestItemId).ToList();
                    ajaxResponse.Data = result;
                    ajaxResponse.Success = true;
                }
            }
            context.Response.Write(ajaxResponse.ToJson());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}